  <!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>WebSocket 示例</title>
    </head>
    <body>
      <script>
        // 实例化 socket
        const ws = new WebSocket('wss://socketsbay.com/wss/v2/1/demo/')
        // 监听连接的建立
        ws.onopen = function(ev) {
          console.log('建立连接...')
          ws.send('Hello WebSockets!')
        }
        // 监听连接的断开
        ws.onclose = function(ev) {
          console.log('断开连接...')
        }
        // 监听 socket 服务器消息
        ws.onmessage = function(ev) {
          console.log('收到消息: ' + ev.data)
        }
      </script>
    </body>
  </html>